﻿'Params
'track (Required (unless mbid)] : The track name
'artist (Required (unless mbid)] : The artist name
'mbid (Optional) : The musicbrainz id for the track
'autocorrect[0|1] (Optional) : Transform misspelled artist and track names into correct artist and track names, returning the correct version instead. The corrected artist and track name will be returned in the response.
'api_key (Required) : A Last.fm API key.
'Auth
'This service does not require authentication. 

Public Structure TrackGetTopTagsResponse
    Public tags() As Tag
End Structure

Public Class TrackGetTopTags
    Inherits BaseRequest
    Dim name As String = ""
    Dim artist As String = ""
    Dim album As String = ""
    Dim mbid As String = ""
    Dim autocorrect As String = ""

	Public xmlresponse As XDocument = Nothing

    Public Sub New(name As String, artist As String, mbid As String, autocorrect As String)
        Me.name = name
        Me.artist = artist
        Me.mbid = mbid
        Me.autocorrect = autocorrect

    End Sub

    Public Sub sendRequest()
        ClearMembers()

        AddMember("method", "track.getTopTags")

        AddMember("track", name, String.IsNullOrEmpty(mbid))
        AddMember("artist", artist, String.IsNullOrEmpty(mbid))
        AddMember("mbid", mbid, False)
        AddMember("autocorrect", autocorrect, False)
        AddMember("api_key", My.Settings.api_key, False)

        xmlresponse = sendGETResponse(False)
    End Sub

    Public Function getResponse() As TrackGetTopTagsResponse
        Dim response As TrackGetTopTagsResponse = Nothing
        Dim count As Integer
        Try
            count = xmlresponse.<lfm>.<toptags>.<tag>.Count()
        Catch ex As Exception
            Return response
        End Try
        If (count > 0) Then
            ReDim response.tags(count - 1)
            For i As Integer = 0 To count - 1
                response.tags(i) = New Tag(xmlresponse.<lfm>.<toptags>.<tag>(i))
            Next
        End If
        Return response
        Return New TrackGetTopTagsResponse
    End Function
End Class
